package com.easy.life.controller;


import com.easy.life.common.R;
import com.easy.life.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.easy.life.service.UserService;




/**
 * 
 *
 * @author xuhbin
 * @email a2712136826@qq.com
 * @date 2021-02-27 14:51:15
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 用户登录
     */
    @PostMapping("/login")
    public R login(@RequestParam String username,@RequestParam String password){

        return userService.login(username,password);
    }
    /**
     * 用户注册
     */
    @PostMapping("/register")
    public R register(@RequestParam String username,@RequestParam String password,
                      @RequestParam String phone,@RequestParam String code){
        return userService.register(username,password,phone,code);
    }
    /**
     * 用户注册时判断用户是否存在
     */
    @GetMapping("/isUser/{username}")
    public R isUser(@PathVariable("username") String username){
        return userService.isUser(username);
    }
    /**
     * 提供用户个人信息
     */
    @GetMapping("/getUser")
    public R getUserById(@RequestParam Long userId){
        UserEntity user = userService.getById(userId);
        return R.ok().put("data",user);
    }

}
